<template>
  <a-layout>
    <a-layout-sider v-model:collapsed="collapsed" :trigger="null" collapsible>
      <div class="logo">
          <img src="https://www.antdv.com/assets/logo.1ef800a8.svg">
          <span v-show="!collapsed">智能泊车中台</span>
      </div>
      <a-menu 
        v-model:selectedKeys="selectedKeys" 
        theme="dark" 
        mode="inline"
        @click="go">
        <a-menu-item key="/home/user">
          <user-outlined />
          <span>用户管理</span>
        </a-menu-item>
        <a-menu-item key="/home/product">
          <video-camera-outlined />
          <span>商品管理</span>
        </a-menu-item>
        <a-menu-item key="/home/category">
          <upload-outlined />
          <span>分类管理</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 5">
        <menu-unfold-outlined
          v-if="collapsed"
          class="trigger"
          @click="() => (collapsed = !collapsed)"
          :style="{fontSize:'18px'}"
        />
        <menu-fold-outlined  v-else class="trigger" @click="() => (collapsed = !collapsed)" />
      </a-layout-header>
      <a-layout-content
        :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '580px' }"
      >
      <!-- 二级路由出口 -->
       <router-view></router-view>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script lang="ts">
import {
  UserOutlined,
  VideoCameraOutlined,
  UploadOutlined,
  MenuUnfoldOutlined,
  MenuFoldOutlined,
} from '@ant-design/icons-vue';
import { defineComponent, ref } from 'vue';
import {useRouter} from 'vue-router'
import {IMenu} from '../types'
export default defineComponent({
  components: {
    UserOutlined,
    VideoCameraOutlined,
    UploadOutlined,
    MenuUnfoldOutlined,
    MenuFoldOutlined,
  },
  
  setup() {
    const router=useRouter()
    //定义collapsed变量，用来控制左侧菜单栏的收缩状态，初始值为false,表示
    let collapsed=ref<boolean>(false)
    let selectedKeys= ref<string[]>(['/home/user'])
   
    const go=(e:IMenu):void=>{     
      let path=e.key
      router.push(path)      
    }
    return {
      selectedKeys,
      collapsed,
      go
    };
  },
});
</script>
<style>
.logo{
  height: 50px;
  color: white;
  font-family: '华文琥珀';
  font-size: 22px;
  line-height: 50px;
  text-align: center;
}
.logo img{
  width: 30px;
  height: 30px;
  border-radius: 50%;
}
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 14px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.3);
  margin: 16px;
}

.site-layout .site-layout-background {
  background: #fff;
}
</style>